//
//  MLAFundsPayDetailVC.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/21.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAFundsPayDetailVC.h"
#import "MLABaseShadowTableCell.h"
#import "MLAFundsPaybleModel.h"

@interface MLAFundsPayDetailVC () {
    MLABaseShadowTableCell *cell;
    MLAFundsPaybleModel *model;
}

@end

@implementation MLAFundsPayDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];

    [self configTitle:@"费用详情"];
    
    self.tableView.rowHeight = 176;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    [self loadData];
}

#pragma mark - LoadData
- (void)loadData {
    [super loadData];
    
    NSDictionary *params = @{@"id":_modelId};
    [MLAHttpManage postHostType:MLAHttpHostType_Api api:kRunWaterDetail params:params success:^(id  _Nonnull response, NSString * _Nonnull msg) {
        self->model = [MLAFundsPaybleModel mj_objectWithKeyValues:response];
        [self.tableView reloadData];
    } failure:^{
        
    }];
}

#pragma mark - tableview datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return model? 1: 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (!cell) {
        cell = [[MLABaseShadowTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        UILabel *titleLbl = [[UILabel alloc] init];
        titleLbl.font = CX_GetNormalFont(16);
        titleLbl.textColor = CX_GetColorTitle();
        [cell.shadowView addSubview:titleLbl];
        [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.mas_equalTo(19);
        }];
        
        UILabel *numberLbl = [[UILabel alloc] init];
        numberLbl.font = CX_GetNormalFont(12);
        numberLbl.textColor = CX_GetColorTitle();
        [cell.shadowView addSubview:numberLbl];
        [numberLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(titleLbl.mas_bottom).offset(18);
        }];
        
        UILabel *shopNameLbl = [[UILabel alloc] init];
        shopNameLbl.font = CX_GetNormalFont(12);
        shopNameLbl.textColor = CX_GetColorTitle();
        [cell.shadowView addSubview:shopNameLbl];
        [shopNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(numberLbl.mas_bottom).offset(9);
        }];
        
        UILabel *usernameLbl = [[UILabel alloc] init];
        usernameLbl.font = CX_GetNormalFont(12);
        usernameLbl.textColor = CX_GetColorTitle();
        [cell.shadowView addSubview:usernameLbl];
        [usernameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(shopNameLbl.mas_bottom).offset(9);
        }];
        
        UILabel *payNumLbl = [[UILabel alloc] init];
        payNumLbl.font = CX_GetNormalFont(12);
        payNumLbl.textColor = CX_GetColorBlue();
        [cell.shadowView addSubview:payNumLbl];
        [payNumLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.top.equalTo(usernameLbl.mas_bottom).offset(20);
        }];
        
        UILabel *startDateLbl = [[UILabel alloc] init];
        startDateLbl.font = CX_GetNormalFont(10);
        startDateLbl.textColor = CX_GetColorHex(0x999999, 1);
        [cell.shadowView addSubview:startDateLbl];
        [startDateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
            make.top.mas_equalTo(24);
        }];

        UILabel *stateLbl = [[UILabel alloc] init];
        stateLbl.font = CX_GetNormalFont(14);
        stateLbl.textColor = CX_GetColorHex(0x6B7178, 1);
        [cell.shadowView addSubview:stateLbl];
        [stateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-20);
            make.right.mas_equalTo(-15);
        }];
        
        startDateLbl.text = model.ctime;
        payNumLbl.text = [NSString stringWithFormat:@"总计：%@元",model.money];
        usernameLbl.text = [NSString stringWithFormat:@"缴费人：%@",model.pay_the_fees_name];
        shopNameLbl.text = [NSString stringWithFormat:@"商户名：%@",model.commercial_tenant_name];
        numberLbl.text = [NSString stringWithFormat:@"商铺号：%@",model.commercial_tenant_mark];
        titleLbl.text = model.type_name;
        if (model.type.integerValue == 1) {
            stateLbl.text = @"支出";
        } else if (model.type.integerValue == 2) {
            stateLbl.text = @"收入";
        }
        
        /*
         startDateLbl.text = @"2018.9.9 12：21";
         payNumLbl.text = @"总计：4000元";
         usernameLbl.text = @"缴费人：张三";
         shopNameLbl.text = @"商户名：xx有限公司";
         numberLbl.text = @"商铺号：A001";
         titleLbl.text = @"三季度物业费";
         stateLbl.text = @"收入/支出";

         */
    }
    
    return cell;
}


@end
